package com.etc.traval.bizimpl;

import java.util.List;

import com.etc.traval.biz.UserBiz;
import com.etc.traval.dao.UserDao;
import com.etc.traval.daoimpl.UserDaoImpl;
import com.etc.travel.entity.User;

public class UserBizImpl implements UserBiz{

	UserDao dao=new UserDaoImpl();
	
	@Override
	public User UserLogin(int id, String pwd) {
		try{
			
			if(pwd== "^([A-Z]|[a-z]|[0-9]|[`~!@#$%^&*()+=|{}':;',\\\\[\\\\].<>/?~��@#��%����&*��������+|{}��������������'��������]){6,20}$"){
				return null;
			}
		}catch(Exception e){
		    return null;	
		}
		return dao.UserLogin(id, pwd);
	}

	@Override
	public boolean UserRegister(User user) {
		try{
			if (!(user.getUser_sex().equals("男")||user.getUser_sex().equals("女"))) {
				return false;
			}
			if(user.getUser_pwd()== "^([A-Z]|[a-z]|[0-9]|[`~!@#$%^&*()+=|{}':;',\\\\[\\\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“'。，、？]){6,20}$"){
				return false;
			}
			if(!user.getUser_status().equals("用户")){
				return false;
			}
			if (user.getUser_name()==null||user.getUser_name().equals("")) {
				return false;
			}
			if(user.getUser_tel().length()!=11){
				return false;
			}
		}catch(Exception e){
		    return false;	
		}
		return dao.UserRegister(user);
	}

	@Override
	public User queryUserById(int id) {
		if(id<10000){
			return null;
		}
		return dao.queryUserById(id);
	}

	@Override
	public boolean updatePwdById(int id, String oldpwd,String newpwd) {
		if(id<10000){
			return false;
		}
		if(newpwd=="^([A-Z]|[a-z]|[0-9]|[`~!@#$%^&*()+=|{}':;',\\\\[\\\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“'。，、？]){6,20}$"){
			return false;
		}
		if (oldpwd=="^([A-Z]|[a-z]|[0-9]|[`~!@#$%^&*()+=|{}':;',\\\\[\\\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“'。，、？]){6,20}$") {
			return false;
		}
		return dao.updatePwdById(id,oldpwd,newpwd);
	}

	@Override
	public boolean addUserMoneyById(int id, double money) {
		if(id<10000){
			return false;
		}
		if(money<0){
			return false;
		}
		return dao.addUserMoneyById(id, money);
	}

	@Override
	public boolean reduceUserMoneyById(int id, double money) {
		if(id<10000){
			return false;
		}
		if(money<0){
			return false;
		}
		return dao.reduceUserMoneyById(id, money);
	}

	@Override
	public User queryUserByName(String name) {
		// TODO Auto-generated method stub
		return dao.queryUserByName(name);
	}

	@Override
	public User queryUserByTel(String tel) {
		// TODO Auto-generated method stub
		return dao.queryUserByTel(tel);
	}

	@Override
	public int checktel(String tel) {
		// TODO Auto-generated method stub
		return dao.checktel(tel);
	}

	@Override
	public List<User> queryalluser() {
		// TODO Auto-generated method stub
		return dao.queryalluser();
	}

	@Override
	public boolean updatePwdById(int id, String newpwd) {
		// TODO Auto-generated method stub
		return dao.updatePwdById(id, newpwd);
	}

}
